package com.haier.service;

import com.haier.dao.classRoom.ClassRoomDao;
import com.haier.pojo.ClassRoom;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import javax.annotation.Resource;

@Service
public class ClassRoomServiceImpl implements ClassRoomService {

    @Resource
    private PlatformTransactionManager transactionManager;

    @Resource
    private ClassRoomDao classRoomDao;

    @Override
    public ClassRoom selectClassRoom(Integer id) {
        return classRoomDao.selectClassRoom(id);
    }

    /***
     * 单数据源  单一事务 测试
     * @param classRoom
     * @return
     */
    @Override
    public Integer insClassRoom(ClassRoom classRoom) {

        TransactionStatus transaction = transactionManager.getTransaction(new DefaultTransactionDefinition());
        try{
            int s =   classRoomDao.insClassRoom(classRoom);
            Integer a = 0;
            Integer b= 10;
            System.out.println(b/a);
            transactionManager.commit(transaction);
            return s;
        }catch (Exception e){
            transactionManager.rollback(transaction);
        }
        return null;
    }
}
